package com.gitee.huxing.course.netty.server.initializer;

import com.gitee.huxing.course.netty.server.adpater.ServiceChannelHandlerAdpater;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * @Description:
 * @ProjectName: JavaCourse
 * @Package: com.gitee.huxing.course.netty.servce.adpater
 * @ClassName: ServiceChannelHandlerAdpater
 * @Author: huxing
 * @DateTime: 2021-08-20 下午6:51
 */

public class ServerChannelInitalier extends ChannelInitializer<SocketChannel> {

    /** 返回的消息 **/
    private String message;

    public ServerChannelInitalier(String message){
        this.message = message;
    }

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        ChannelPipeline pipeline = socketChannel.pipeline();
        pipeline.addLast(new HttpServerCodec());
        pipeline.addLast(new HttpObjectAggregator(1024 * 1024));
        pipeline.addLast(new ServiceChannelHandlerAdpater(message));
    }
}
